package zoo;

import zoo.animals.Animal;
import zoo.animals.mammal.Cat;
import zoo.animals.mammal.Dog;
import zoo.workers.Feeder;
import zoo.workers.Worker;

import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;

/**
 * Created with IntelliJ IDEA.
 * User: platonovv
 * Date: 25.11.13
 * To change this template use File | Settings | File Templates.
 */
public class Zoo {

    private List<Animal> animals;
    private List<Worker> workers;

    public Zoo(Worker... workers) {
        this.workers = Arrays.asList(workers);
    }
    public Zoo(Animal... animals) {
        this.animals = Arrays.asList(animals);
    }

    public Zoo() {
        Animal cat = new Cat("Winston", 5);
        add(cat);
        Animal dog = new Dog("Hector", 10);
        add(dog);
        Feeder worker = new Feeder("Joshua");
        worker.add(dog);
        worker.add(cat);
        add(worker);
    }

    public void add(Animal animal) {
        if (animals == null)
            animals = new ArrayList();
        animals.add(animal);
    }

    public void add(Worker worker) {
        if (workers == null)
            workers = new ArrayList();
        workers.add(worker);
    }

    public void greetings() {
        for (Worker worker : workers) {
            worker.voice();
        }
    }

    public void cacophony() {
        for (Animal animal : animals) {
            animal.voice();
        }
    }

    public void feed() {
        for (Worker worker : workers) {
            if (worker instanceof Feeder)
                ((Feeder) worker).feed();
        }
    }
}
